1. Field of the Invention
The present invention relates to a microprocessor that operates according to a program. Particularly, the present invention relates to a real-time processor that executes a predetermined operation defined by a program correctly at a predetermined time.
2. Description of the Background Art
In accordance with the development of microprocessor techniques, microprocessors are now beginning to be used also for the control of hardware which have been conventionally carried out by an application specific circuit. It is important to adjust the operation timing so that the microprocessor outputs an appropriate control signal at an appropriate time in order to control the hardware properly. This operation timing must not be earlier nor delayed than the predetermined time.
For the adjustment of the operation timing by the microprocessor, the method of inserting a NOP (No Operation) instruction or empty loop in the program to delay execution of the program for a required period of time has been generally employed. However, the period of time required for the microprocessor to execute the program varies in a complex manner depending upon various factors such as the value of the processed data, the memory operation time (access delay), the frequency of the clock signal, and the like. When the program becomes extremely complicated, it will become difficult to calculate the appropriate delay time during creation of the program.
In order to realize a system of high reliability, it is desirable to include the mechanism to detect occurrence of an abnormal event, if any, that negates execution of a predetermined operation at a predetermined time, and carry out a recovery procedure.
One conventional art directed to solve such a problem is known as the microprocessor disclosed in Japanese Patent Laying-Open No. 5-233277. FIG. 1 is a block diagram showing a structure of the microprocessor disclosed in this publication. A microprocessor 901 includes a processing unit 902 that executes an instruction code, a time adjustment unit 903 adjusting the time between instruction codes, and a buffer 908 connected to an external bus. Time adjustment unit 903 includes a time measurement unit 904 measuring the time between two instruction codes, a certain time set unit 905 setting a certain time, a difference arithmetic unit 906 computing the difference between the time set by certain time set unit 905 and the time measured by time measurement unit 904, and an idle state insertion unit 907 inserting an idle state for a period of time corresponding to the difference obtained by difference arithmetic unit 906.
Upon execution of the first instruction (instruction indicating initiation of measurement) by processing unit 902, the value of time measurement unit 904 is initialized to 0, and the value thereof is incremented at a constant time period. Here, it is assumed that the time when the first instruction is executed is t901.
Processing unit 902 then executes the second instruction (instruction indicating end of measurement). Here, it is assumed that the time when the second instruction is executed is t902. Difference arithmetic unit 906 calculates the difference between the value set by certain time set unit 905 and the time measured by time measurement unit 904 (=t902−t901), and provides that value to idle state insertion unit 907. Idle state insertion unit 907 suppresses the operation of processing unit 902 until the elapse of the time corresponding to the difference calculated by difference arithmetic unit 906. Here, it is assumed that the time when processing unit 906 resumes its operation is t903.
By the operation described above, the difference calculated by difference arithmetic unit 906 becomes smaller if the time of elapse from t901 to t902 becomes longer, whereby the suppression time of processing unit 902 becomes shorter. In contrast, a shorter elapse time from t901 to t902 results in a larger difference calculated by difference arithmetic unit 906, whereby the suppression time of processing unit 902 becomes longer. Thus, the suppression time of processing unit 902 varies so as to compensate for change in the elapse time from t901 to t902. The elapse time from t901 to t903 is determined depending only on the value set at certain time set unit 905. The elapse time from t901 to t903 is kept constant irrespective of the execution speed of processing unit 902 that is altered according to various factors.
However, only adjustment of the elapse time between two instructions is taken into consideration in the microprocessor disclosed in Japanese Patent Laying-Open No. 5-233277. As to the method of altering the value of time measurement unit 904 according to an instruction in the program, only the method of initializing the value of time measurement unit 904 to 0 in response to execution of an instruction to initiate measurement by processing unit 902 is disclosed. The microprocessor thereof cannot adjust the elapse time between arbitrary instructions in association with execution of the instruction that designates initiation of measurement.
Also, the time that can be measured by time measurement unit 904 is finite. In order to prevent overflow of time measurement unit 904, processing unit 902 must execute the instruction designating initiation of measurement at least once within a limited period of time. This microprocessor is not suited for applications in which a certain instruction is repeatedly executed infinitely at a constant time interval.
Furthermore, the case where the difference calculated by difference arithmetic unit 906 attains a negative value, i.e., when the elapse time from t901 to t902 becomes unexpectedly long to exceed t903, is not taken into consideration. There was problem that this microprocessor could not carry out the recovery procedure in the case where the difference calculated by difference arithmetic unit 906 provides a negative value.